-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mark all scripted field queries as expensive #59658
Mark all scripted field queries as expensive #59658
Conversation
This will cause them to fail if you don't have permission to execute expensive queries.
Pinging @elastic/es-search (:Search/Search) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a couple of nits, LGTM otherwise
private void checkAllowExpensiveQueries(QueryShardContext context) { | ||
if (context.allowExpensiveQueries() == false) { | ||
throw new IllegalArgumentException( | ||
"queries cannot be executed against [script] fields while [" + ALLOW_EXPENSIVE_QUERIES.getKey() + "] is set to [false]." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use the constant from the mapper? content type I think it is called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we rather throw ElasticsearchException also, and why doesn't the context expose a check method instead that accepts for instance a message? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we rather throw ElasticsearchException also, and why doesn't the context expose a check method instead that accepts for instance a message? :)
That would probably be a good choice.
I have no idea why we were throwing ElasticsearchException when we were. It feels like this is what IAE is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea why we were throwing ElasticsearchException when we were. It feels like this is what IAE is for.
I figured it out - we translate all exceptions thrown when building a query into a QueryShardException
which is always a 400.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why doesn't the context expose a check method instead that accepts for instance a message? :)
It really is a good idea. I took a look at it and, ironically, testing it is kind of a pain. I'll hold off on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we open issues for possible follow-up tasks that we don't want to spend time on right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me give it another go this morning!
@Override | ||
public Query existsQuery(QueryShardContext context) { | ||
checkAllowExpensiveQueries(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe one day we will a base class for runtime mapper field types that does this in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably!
This will cause them to fail if you don't have permission to execute
expensive queries.
Relates to #59332